package com.migration.service.impl;

import com.migration.model.olddb.RaFaultChainsDetail;
import com.migration.model.olddb.RaFaultChainsMeasure;
import com.migration.service.RiskChainDetailService;
import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 事故链详情服务实现类
 */
@Service
public class RiskChainDetailServiceImpl implements RiskChainDetailService {

    @Override
    public List<RaFaultChainsDetail> getAllFaultChainsDetails(EntityManager oldEntityManager) {
        CriteriaBuilder oldCriteriaBuilder = oldEntityManager.getCriteriaBuilder();
        CriteriaQuery<RaFaultChainsDetail> detailQuery = oldCriteriaBuilder.createQuery(RaFaultChainsDetail.class);
        Root<RaFaultChainsDetail> detailRoot = detailQuery.from(RaFaultChainsDetail.class);
        detailQuery.select(detailRoot);
        detailQuery.where(oldCriteriaBuilder.equal(detailRoot.get("isDel"), (byte) 0));
        return oldEntityManager.createQuery(detailQuery).getResultList();
    }
    
    @Override
    public List<RaFaultChainsMeasure> getAllFaultChainsMeasures(EntityManager oldEntityManager) {
        CriteriaBuilder oldCriteriaBuilder = oldEntityManager.getCriteriaBuilder();
        CriteriaQuery<RaFaultChainsMeasure> measureQuery = oldCriteriaBuilder.createQuery(RaFaultChainsMeasure.class);
        Root<RaFaultChainsMeasure> measureRoot = measureQuery.from(RaFaultChainsMeasure.class);
        measureQuery.select(measureRoot);
        return oldEntityManager.createQuery(measureQuery).getResultList();
    }
} 